﻿

namespace FacebookXmpp.Parse
{
	internal class XmlAttributeValue : XmlParseState
    {
        private string _key;

        public XmlAttributeValue(XmlParseState from, string key)
            : base(from)
        {
            _key = key;
        }

        public override XmlParseState Parse(StringParser parser)
        {
            if (parser.PauseIfNearEnd(2))
                return this;

            string value;
            if (parser.IsNext("\""))
            {
                parser.Consume("\"");
                if (parser.Find("\"") == -1)
                {
                    parser.Pause();
                    return this;
                }
                value = parser.ConsumeTo('"', false);
                parser.Consume("\"");
            }
            else
            {
                value = parser.ConsumeTo(' ', true);

                if (parser.IsPaused)
                    return this;
            }

			_builder.Current.AddAttribute( _key, value );
            return new XmlElementDefinition(this);
        }
    }
}